﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AMS.DD35.DbLoader.Controllers;

namespace AMS.DD35.DbLoader.Views
{
    public partial class BrowserDialog : Form
    {
        private IBrowserController _controller;

        #region Accessors
        public string NewButtonText
        {
            get { return btnNew.Text; }
            set { btnNew.Text = value; }
        }

        public string BrowserName
        {
            get { return this.Text; }
            set { this.Text = value; }
        }

        public object SelectedItem
        {
            get { return lbItems.SelectedItem; }
        }

        public ListBox.SelectedObjectCollection SelectedItems
        {
            get { return lbItems.SelectedItems; }
        } 
        #endregion

        public BrowserDialog(IBrowserController controller)
        {
            InitializeComponent();

            this._controller = controller;
        }

        public void Populate(IEnumerable<object> populateList)
        {
            lbItems.Items.Clear();
            foreach (object o in populateList)
            {
                AddNew(o);
            }
        }

        public void AddNew(object o)
        {
            lbItems.Items.Add(o);
        }

        private void HandleBtnEdit_Click(object sender, EventArgs e)
        {
            _controller.Edit();
        }

        private void HandleBtnAccept_Click(object sender, EventArgs e)
        {
            // tell controller to accept (DialogResult.OK) selected item(s) and present to whichever master created it
            _controller.Accept();
        }

        private void HandleBtnCancel_Click(object sender, EventArgs e)
        {
            // tell controller to quit (DialogResult.Cancel) with no action
            _controller.Cancel();
        }

        private void HandleBtnNew_Click(object sender, EventArgs e)
        {
            // tell controller to spawn appropriate Editor, then Populate this Browser on done creating
            _controller.CreateNewItem();
        }
    }
}
